package offer;

import java.util.ArrayList;
import java.util.List;

public class offer57_II {
    public static void main(String[] args) {
        Solution solution = new Solution();
        solution.findContinuousSequence(9);
    }


    static class Solution {
        public int[][] findContinuousSequence(int target) {
            List<int[]> list = new ArrayList<>();
            int i = 1, j = 1;
            int sum = 0;
            while(i<=j && i <= target/2){
                if(sum == target){
                    int[] arr = new int[j-i];
                    for(int k = i; k < j; k++){
                        arr[k-i] = k;
                    }
                    list.add(arr);
                    sum -= i;
                    i++;
                } else if(sum > target){
                    sum -= i;;
                    i++;
                } else {
                    sum += j;
                    j++;
                }
            }
            return list.toArray(new int[list.size()][]);
        }
    }
}
